# Maintainer: Feng Shu <tumashu@163.com>

_realname=marisa
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=0.2.6
pkgrel=5
pkgdesc="Matching Algorithm with Recursively Implemented StorAge (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url="https://github.com/s-yata/marisa-trie"
license=('spdx:BSD-2-Clause')
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-autotools")
source=("https://github.com/s-yata/marisa-trie/archive/v${pkgver}/${_realname}-${pkgver}.tar.gz"
       "001-tools-makefile.patch")
sha256sums=('1063a27c789e75afa2ee6f1716cc6a5486631dcfcb7f4d56d6485d2462e566de'
            'd3ec2637462ac3331f0c6bcba9b8552bca4819321df265b3fd895547bbf75717')

prepare() {
  cd "marisa-trie-${pkgver}"
  patch -p0 -i "${srcdir}"/001-tools-makefile.patch
  autoreconf -fiv
}

build() {
  mkdir build-${MSYSTEM} && cd build-${MSYSTEM}

  local -a _extra_config
  if [[ ${CARCH} == x86_64 ]]; then
    _extra_config+=("--enable-sse3")
  fi
 
  ../marisa-trie-${pkgver}/configure \
    --enable-shared \
    "${_extra_config[@]}"

  make
}

package() {
  cd "${srcdir}/build-${MSYSTEM}"

  make DESTDIR="${pkgdir}" install

  install -Dm644 "${srcdir}"/marisa-trie-${pkgver}/COPYING.md \
    "${pkgdir}"${MINGW_PREFIX}/share/licenses/${_realname}/COPYING
}
